package cn.yitun.chat.yitunservermanagecore.general.manage.core.controller;

import cn.yitun.chat.yituncommonmessage.result.ResultMessage;
import cn.yitun.chat.yitungeneral.annotation.parameter.JsonDefine;
import cn.yitun.chat.yitungeneral.annotation.parameter.RequestParameter;
import cn.yitun.chat.yitunservercommonlib.annotation.Log;
import cn.yitun.chat.yitunservercommonlib.basebean.web.JwtUserDto;
import cn.yitun.chat.yitunservercommonlib.crud.yitun.BaseController;
import cn.yitun.chat.yitunservercommonlib.dataentity.dto.login.OnlineUserDto;
import cn.yitun.chat.yitunservercommonlib.dataentity.vo.login.OnlineUserVo;
import cn.yitun.chat.yitunservermanagecore.general.bridge.auth.annotation.PermissionMapping;
import cn.yitun.chat.yitunservermanagecore.general.manage.core.service.OnlineService;
import cn.yitun.chat.yitunservermanagecore.general.manage.index.service.IndexService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/manage/core")
@RestController
public class OnlineController extends BaseController {
	@Autowired
	private OnlineService onlineService;

	@Autowired
	private IndexService indexService;
	@RequestParameter
	@PermissionMapping(name = "在线用户列表", perms = "sys:online")
	@PostMapping("/online/page")
	public ResultMessage list(JwtUserDto jwtUserDto, @JsonDefine OnlineUserDto onlineUserDto) {
		checkRootPage(onlineUserDto, jwtUserDto);
		PageHelper.startPage(onlineUserDto.getCurrentPageNo() , onlineUserDto.getPageSize());
		List<OnlineUserVo> list = onlineService.list(onlineUserDto) ;
		ResultMessage rm = new ResultMessage();
		rm.bodyPut("page", new PageInfo<>(list));
		return rm;
	}

	@Log("用户强制退出")
	@RequestParameter
	@PermissionMapping(name = "更新用户密码等信息", perms = "sys:root:remove")
	@PostMapping("/online/forceLogout/{userId}")
	public ResultMessage forceLogout(JwtUserDto jwtUserDto, @PathVariable("userId") Long userId) {
		indexService.forceLogout(userId , jwtUserDto);
		return new ResultMessage();
	}

//	@GetMapping("/sessionList")
//	public ResultInfo sessionList() {
//		return ResultInfo.ok(sessionService.sessionList());
//	}


}
